package com.zombie.logic.object;

import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.math.Vector2;
import com.zombie.state.GameState;

public class CrawlingZombie extends Zombie {

	boolean isHoldPlayer = false;
	int holdingTime = 1000;
	long holdingStarted;
	
	public CrawlingZombie(float x, float y, String image, int w, int h) {
		super(x, y, image, w, h);
	}

	public CrawlingZombie(float x, float y, String image) {
		this(x, y, image, 52, 24);
	}
	
	protected void stepSound(){
		
	}
	
	protected void hit() {
		super.hit();
		if (GameState.time < holdingStarted+holdingTime*2)
			return;
		isHoldPlayer = true;
		holdingStarted = GameState.time;
	}
	
	
	@Override
	public void update(float delta) {
		super.update(delta);
		if (isDead() || wait)
			return;
		
		body.setTransform(body.getWorldCenter().x,body.getWorldCenter().y, MathUtils.degRad*angle,false);
		if (isHoldPlayer){
			Player p = GameState.getInstance().player;
			if (distanceToObject(p) > Math.min(size.x, size.y)/2+2){
				float angl = p.getAngleToObject(this);
				float x1 = getVelocity()*2*MathUtils.cos(MathUtils.degRad*angl);
				float y1 = getVelocity()*2*MathUtils.sin(MathUtils.degRad*angl);
				p.body.applyForceToCenter(x1,y1);
				System.out.println("hold player!");
			}
		}
		if (GameState.time > holdingStarted+holdingTime)
			isHoldPlayer = false;
	}
	
	public void draw(SpriteBatch batch, ShapeRenderer shapeBatch){
		super.draw(batch, shapeBatch);
//		if (isHoldPlayer){
//			Player p = GameState.player;
//			for(int i = 0; i < 10;i++){
//				double angl = p.getAngleToObject(this);
//				double x1 = i*getVelocity()*2*FastTrig.cos(Math.toRadians(angl));
//				double y1 = i*getVelocity()*2*FastTrig.sin(Math.toRadians(angl));
//
//			}
//		}
	}
	
}
